import 'package:flutter/material.dart';
import 'dart:math' as math;

class ContainerTestRoute extends StatefulWidget {
  const ContainerTestRoute({super.key});

  // 这里变量的类型换成State才不会有警告。但不知道会不会有其它影响
  @override
  State<ContainerTestRoute> createState() => _ContainerTestRouteState();
}

class _ContainerTestRouteState extends State<ContainerTestRoute> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text("测试一些布局相关的东西")),
      backgroundColor: const Color.fromARGB(0, 1, 1, 12),
      body: getContentView(),
    );
  }
}

Widget getContentView() {
  return Column(
    children: [
      const Padding(
        padding: EdgeInsets.all(10),
      ),
      const DecoratedBox(
        decoration: BoxDecoration(color: Colors.red),
        //默认原点为左上角，左移20像素，向上平移5像素
        child: Text("Hello world"),
      ),
      const Padding(
        padding: EdgeInsets.all(30),
      ),
      DecoratedBox(
        decoration: const BoxDecoration(color: Colors.red),
        //默认原点为左上角，左移20像素，向上平移5像素
        child: Transform.translate(
          offset: const Offset(-25.0, -15.0),
          child: Transform.rotate(
            angle: math.pi / 2,
            child: const Text("Hello world"),
          ),
        ),
      ),
      const Padding(padding: EdgeInsets.all(30)),
      DecoratedBox(
        decoration: const BoxDecoration(color: Colors.red),
        child: Transform.rotate(
            //旋转90度
            angle: math.pi / 2,
            child: Transform.translate(
              offset: const Offset(-25.0, -15.0),
              child: const Text("Hello world"),
            )),
      ),
    ],
  );
}

/// 单行容器类。（子类为 Row 加 MainAxisAlignment.spaceEvenly 属性时）自动适配间隔
class SingleLineFittedBox extends StatelessWidget {
  const SingleLineFittedBox({Key? key, this.child}) : super(key: key);
  final Widget? child;

  @override
  Widget build(BuildContext context) {
    return LayoutBuilder(
      builder: (_, constraints) {
        return FittedBox(
          child: ConstrainedBox(
            constraints: constraints.copyWith(
              //让 maxWidth 使用屏幕宽度
              // maxWidth: constraints.maxWidth, // 这种会等于没加 FittedBox 的 Row
              minWidth: constraints.maxWidth,
              maxWidth: double.infinity,
            ),
            child: child,
          ),
        );
      },
    );
  }
}
